// This java script file contains java scripts for the client side, using jquery, and ajax as implemented by jquery 
// TODO delete Checkuser
function Checkuser(username)
{
	$.ajax({
		 url:"ajax_new.php",
		 data:"do=Checkuser="+username,
		 async:true,
		 type:"POST",
		 success:function(result)
		  {
			 alert('הסיסמא נשלחה למייל שלך');
		  }
	});
}
function show_project_ajax(id,name_session)
{
   
   $.ajax({
	      url:"ajax2.php",
		  data:"do=show_project_ajax&id="+id+"&name_session="+name_session,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			$('#content').html(result);
        get_name_project_for_add_task(id);
			 $('#select_customer').val('none');
			 
		  }
	   
	   
	   });
	  
	
}
 
function get_name_project_for_add_task(id)
{
   
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=get_name_project_for_add_task&id="+id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#add_task h3 span').html(result);
		  }
	   
	   
	   });
	  
	
}
 
function show_project_ajax_find(name_project,name_session)
{
	$('#span_send_task').hide();
   $.ajax({
	      url:"ajax2.php",
		  data:"do=show_project_ajax_find&name_project="+name_project+"&name_session="+name_session,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			   $('#content').html(result);
			   $('#add_task h3 span').html(name_project);
			   $('#select_customer').val('none');
		  }
	   
	   
	   });
	    	
	}
function send_new_task(id_project,user_id,temp)
{ $('#add_task  div#loading').css('display','block');
     
   $.ajax({
	      url:"ajax2.php",
		  data:"do=send_new_task&id_project="+id_project+"&"+temp,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
		   $('#all_task').before(result).slideDown('slow');
		    $('#add_task  div#loading').css('display','none'); 
           $('#lightbox, #lightbox_frame').hide();
		
		  }
	   
	   
	   });	
}
	
function new_message(user_id)
{ 
   $.ajax({
	      url:"ajax2.php",
		  data:"do=new_message&user_id="+user_id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#mass #new_message').html(result);
			 
		  
			var x=user_id;
		 if($('#hid_sound_new').val()<=$('#hid_sound_old').val())
			{
				$('#hid_sound_old').val($('#hid_sound_new').val());
			}
			else 
				{
				  	$('#hid_sound_old').val($('#hid_sound_new').val());
					$('embed').remove();
					$('audio').remove();
					
				}
		  }
	   
	   
	   });	
	}
	
	function gomassage(name_class,id_task,id_comment,user_id)
{
   $.ajax({
	      url:"ajax2.php",
		  data:"do=gomassage&id_task="+id_task+"&name_class="+name_class+"&id_comment="+id_comment+"&user_id="+user_id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			
			 document.getElementById('content').innerHTML=result;
			 new_message(user_id);
			 $('#span_send_task').css('display','none');
		  }
	   
	   
	   });	
	}
function change_status(id_status,id_project)
	{
	  $.ajax({
	      url:"ajax2.php",
		  data:"do=change_status&id_status="+id_status+"&id_project="+id_project,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			switch (id_status)
				   {
					  case 1:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_red.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					 break;  
					case 2:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_Orange.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					 break;  
					 case 3:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_Yellow.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					 break;  
					 case 4:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_green.png) no-repeat top right');
					 break;   
					 case 5:
					   $('#postponed'+id).css('background','url(./style/images/deny_x_active.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					 break;   
		  }
		  }

	   });	
	}
	
	function change_status_task(id_status,id_task,id)
	{  
		$('#sbb'+id+' #traficLight').show();
	  $.ajax({
	      url:"ajax2.php",
		  data:"do=change_status_task&id_status="+id_status+"&id_task="+id_task,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			   $('#sbb'+id+' #traficLight').hide();
			switch (id_status)
				   {
					case 1:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_red.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#sbb'+id+' .close_task').css('display','none');
					 break;  
					case 2:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_Orange.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					    $('#sbb'+id+' .close_task').css('display','none');
					 break;  
					 case 3:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_Yellow.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					    $('#sbb'+id+' .close_task').css('display','none');
					 break;  
					 case 4:
					   $('#postponed'+id).css('background','url(./style/images/deny_x.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_green.png) no-repeat top right');
					   $('#sbb'+id+' .close_task').css('display','block');
					 break;   
					 case 5:
					   $('#postponed'+id).css('background','url(./style/images/deny_x_active.png) no-repeat top right');
					   $('#red'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#yellow'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#orange'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					   $('#green'+id).css('background','url(./style/images/status_btn_gray.png) no-repeat top right');
					    $('#sbb'+id+' .close_task').css('display','none');
					 break;   
			
		  }
		  
		  }

	   });	
	}
function send_mail_postponed(info,id)
{ 
	$.ajax({
	      url:"ajax_new.php",
		  data:"do=send_mail_postponed&"+info,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			  
		  $('#if_send').html(result);
		  $('#postponed_message'+id).delay(2000).fadeOut();
			
		  }
	   
	   
	   });	
}
	function insert_message(id_task,content,user_id)//send comment
{      $("#loading"+id_task).css('display','block');
    
   $.ajax({
	      url:"ajax2.php",
		  data:"do=insert_message&id_task="+id_task+"&content="+content+"&user_id="+user_id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			  
			$('#part_comments'+id_task).append(result);
			$('#textarea'+id_task).val("הקלידו תגובה חדשה...");
			$("#loading"+id_task).css('display','none');
		  }
	   
	   
	   });	
	}
function send_mail_contect(id_task,content,user_id)
{      
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=send_mail_contect&id_task="+id_task+"&content="+content+"&user_id="+user_id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
		
			
			$("#loading"+id_task).css('display','none');
		  }
	   
	   
	   });	
	}
	
	 
	function get_new_task()//returns all tasks awaiting admin's aproval
{  
   $.ajax({
	      url:"ajax3.php",
		  data:"do=get_new_task",
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#content').html(result);
			 get_tasks_open_admin();
		  }
	   
	   
	   });	
	}
function get_tasks_open_admin()//returns all current tasks shown in admin main section
{  
   $.ajax({
	      url:"ajax3.php",
		  data:"do=get_tasks_open_admin",
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
		     	$('#content').append(result);
		  }
	   
	   
	   });	
	}	
	
function get_tasks_open(id)//returns all open tasks for a user
{ 
   $.ajax({
	      url:"ajax2.php",
		  data:"do=get_tasks_open&id="+id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
		  
		  	$('#content').html(result);
		  }
	   
	   
	   });	
	}	
function isuser(name_user)
{
 $.ajax({
		 url:"ajax_new.php",
		 data:"do=isuser&name_user="+name_user,
		 async:true,
		 type:"post",
		 success:function(result)
				{  
					 var x=(result);
					 $('#test').html(result);
					
					 if($('#hid_res').val()==0)
					 	{
						    $('#form_new_user').submit();
							
					    }
						else 
						{
							
						  alert('השם משתמש נמצא במערכת');	
						}
				}
	 
	 });	
		
}
function isusercustomer(name_user,id_customer,form)
{
 $.ajax({
		 url:"ajax_new.php",
		 data:"do=isuser&name_user="+name_user,
		 async:true,
		 type:"post",
		 success:function(result)
				{  

					 var x=(result);
					 $('#test').html(result);
					
					 if($('#hid_res').val()==0)
					 	{
						 
							CreateNewUser(name_user,form);
					    }
						else 
						{
							
						  alert('השם משתמש נמצא במערכת');	
						}
				}
	 
	 });	
		
}
function get_edit_profil(id)//returns user details, by user id
{  
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=get_edit_profil&id="+id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
			$('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show(); 
		  }
	   
	   
	   });	
	}	
function update_profil(id,pass,mail,status_send_mail)//users options to update his profil
{  
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=update_profil&id="+id+"&pass="+pass+"&mail="+mail+"&status_send_mail="+status_send_mail,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
			alert('הנתונים נשמרו במערכת');
			$('#lightbox_admin, #lightbox_admin_frame').hide(); 
		  }
	   
	   
	   });	
	}
function selector_status(id_project,id)//returns all tasks for project 
{  
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=selector_status&id_project="+id_project+"&id="+id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
			$('#all_task').html(result);
		  }
	   
	   
	   });	
	}
function selector_all_option(id_project,status,from,to)//returns all tasks for project, by status and date 
{  
   $.ajax({
	      url:"ajax2.php",
		  data:"do=selector_all_option&id_project="+id_project+"&status="+status+"&from="+from+"&to="+to,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
			$('#all_task').html(result);
		  }
	   
	   
	   });	
	}	
function selector_all_option_project(id_customer,status,from,to)//returns all tasks by customer status and date
{  
   $.ajax({
	      url:"ajax_new.php",
		  data:"do=selector_all_option_project&id_customer="+id_customer+"&status="+status+"&from="+from+"&to="+to,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			$('#contectProjectOfStatus').html(result);
		  }
	   
	   
	   });	
	}	
function selector_all_option_customer(id_customer,from,to)//returns all open task between dates
{  
   $.ajax({
	      url:"ajax2.php",
		  data:"do=selector_all_option_customer&id_customer="+id_customer+"&from="+from+"&to="+to,
		  async:true,
		  type:"POST",
		  success:function(result)
		  { 
			//alert(result);
			$('#all_project_customer').html(result);
		  }
	   
	   
	   });	
	}	
function get_from_dashboard(id)
{
 $.ajax({
	    url:"ajax3.php",
		data:"do=get_from_dashboard&id="+id,
		async:true,
		type:"POST",
		success:function (result)
		  {
			  
			  $('#content').html(result);
		  }
		 
	 });	
 	
}	
        
function find_for_task(id_task)
{
 $.ajax({
	    url:"ajax3.php",
		data:"do=find_for_task&id_task="+id_task,
		async:true,
		type:"POST",
		success:function (result)
		  {
			  $('#span_send_task').hide();
			  $('#content').html(result);
			  $('#select_customer').val('none');
		  }
		 
	 });	
 	
}	
function get_all_info_customer(id_customer)
{ $('#select_customer_loader').css('display','block');
 $.ajax({
	     url:"ajax2.php",
		 data:"do=get_all_info_customer&id_customer="+id_customer,
		 async:true,
		 type:"POST",
		 success:function (result)
		  {

			  $('#span_send_task').css('display','none'); 
			  $('#select_customer_loader').css('display','none');
			  
			  $('#content').html(result);
			  
		  }
	  });	
}
/*********************************************ajax_admin****************************************************************/
function goto_control_panel()//returns admin page
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=goto_control_panel",
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#content').html(result);
			 $('#select_customer').val('none');
			 
		  }
	   
	   
	   });	
	}
	

function get_new_form_user()//returns new user form
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=get_new_form_user",
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			  
			 $('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show();
			 
		  }
	   
	   
	   });	
	}	
	
function get_new_form_project()//returns new project form
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=get_new_form_project",
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			  
			 $('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show();
			 
		  }
	   
	   
	   });	
	}
	
function get_new_form_customer()//returns new customer form
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=get_new_form_customer",
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			  
			 $('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show();
			 
		  }
	   
	   
	   });	
	}	
function change_edit_project(id_customer)//returns edit project
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=change_edit_project&id_customer="+id_customer,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#edit_project #project').html(result);
			
		  }
	   
	   
	   });	
	} 
function change_form_edit_user(id_customer)//returns edit user
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=change_edit_project&id_customer="+id_customer,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#form_edit_user #project').html(result);
			
		  }
	   
	   
	   });	
	} 
	
	function change_new_user(id_customer)
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=change_edit_project&id_customer="+id_customer,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('.form_set #project').html(result);
			
		  }
	   
	   
	   });	
}
function change_edit_user(id_customer)
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=change_edit_user&id_customer="+id_customer,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#edit_user #user_name').html(result);
			
		  }
	   
	   
	   });	
	}
	
function change_edit_user_add_project(id_customer)
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=change_edit_user_add_project&id_customer="+id_customer,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			 $('#form_edit_user #project').html(result);
			
		  }
	   
	   
	   });	
	}	
function get_info_project(id_project)//returns info page for project
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=get_info_project&id_project="+id_project,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			$('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show();

			
		  }
	   
	   
	   });	
	}
	
function get_info_user(id_user)
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=get_info_user&id_user="+id_user,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			$('#lightbox_admin_content').html(result);
			$('#lightbox_admin, #lightbox_admin_frame').show();
     		
			
		  }
	   
	   
	   });	
	}
		
function getAdmin(namefunc,id)//מחזיר את כל ההודעות שמחכות לאישור
{ 
   $.ajax({
	      url:"ajax_admin.php",
		  data:"do=Admin"+namefunc+"&id="+id,
		  async:true,
		  type:"POST",
		  success:function(result)
		  {
			$('#Adminedit_user').html(result);
			
		  }
	   
	   
	   });	
	}
function changeActive(nameTable,NameId,id,active)// מקבלת שם טבלה ומשנה את  המצב שלה 
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=changeActive&nameTable="+nameTable+"&id="+id+"&active="+active+"&NameId="+NameId,
		 async:true,
		 type:"post",
		 success:function(result)
				{  
					alert('השינוי בוצע' );
					
					//window.location.reload( false );
					
				}
	 
	 });	
		
}

function get_edit_customer(id_customer)// מקבלת שם טבלה ומשנה את  המצב שלה 
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=get_edit_customer&id_customer="+id_customer,
		 async:true,
		 type:"post",
		 success:function(result)
				{   
					$('#lightbox_admin_content').html(result);
					$('#lightbox_admin, #lightbox_admin_frame').show();
				}
	 
	 });	
		
}
function get_LookProfilCustomer(id_customer)// מקבלת שם טבלה ומשנה את  המצב שלה 
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=get_LookProfilCustomer&id_customer="+id_customer,
		 async:true,
		 type:"post",
		 success:function(result)
				{   
					$('#lightbox_admin_content').html(result);
					$('#lightbox_admin, #lightbox_admin_frame').show();
				}
	 
	 });	
		
}
function add_permissions(id_project,user_id)
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=add_permissions&id_project="+id_project+"&user_id="+user_id,
		 async:true,
		 type:"post",
		 success:function(result)
				{ 
				 getAdmin('edit_user',user_id);
				 $('#er').html(result);
				}
	 
	 });	
		
}	

function CreateNewUserOfCompany(id_custimer)  
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=CreateNewUserOfCompany&id_custimer="+id_custimer,
		 async:true,
		 type:"post",
		 success:function(result)
				{ 
				   
				  $('#test').html(result);
				}
	 
	 });	
		
}
function CreateNewUserOfProject(id_custimer)  
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=CreateNewUserOfProject&id_custimer="+id_custimer,
		 async:true,
		 type:"post",
		 success:function(result)
				{ 
				   
				  $('#test').html(result);
				}
	 
	 });	
		
}

function  CreateNewUser(name_user,form)
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=CreateNewUser&"+form,
		 async:true,
		 type:"post",
		 success:function(result)
				{ 
				  
				   $('#cart div ol').append('<li >'+name_user+'</li> ');
				   $('#cart div ol').append(result);
				}
	 
	 });	
		
}
function  Delete(id,project)
{
 $.ajax({
		 url:"ajax_admin.php",
		 data:"do=Delete&id="+id+"&project="+project,
		 async:true,
		 type:"post",
		 success:function(result)
				{ 
				
				  //alert("הוסרה ההרשאה של המשתמש מהפרוייקט הנוכחי ");
				  $('#cart #'+id).remove();
				}
	 
	 });	
		
}
function  sendWeeklyReport()
{
	 $.ajax({
			 url:"ajax_admin.php",
			 data:"do=sendWeeklyReport",
			 async:true,
			 type:"post",
			 success:function(result)
					{ 
					
					 
					}
		 
		 });	
		
}
	
